package view.components
{
	import flash.events.Event;
	import flash.text.TextField;
	
	import utils.TextTool;
	
	public class IconButton extends LabelButton
	{
		private static var tempText:TextField;
		private var iconText:TextField;
		private var text:String;
		
		public function IconButton(x:int, y:int, id:int, onClickFunction:Function, face:String, text:String, info:String=null)
		{
			super(x, y, id, onClickFunction, face, info);
			this.text = text;
			this.mouseChildren = false;
			initText();
			this.buttonMode = true;
		}
		
		private function initText():void
		{
			if (tempText == null)
			{
				tempText = TextTool.getTextField(800,20,12,0xFFFFFF);
			}
			tempText.text = text;
			
			iconText = TextTool.getTextField(tempText.textWidth + 10,20,12,0xFFFFFF);
			iconText.x = faceImg.width;
			iconText.text = text;
			addChild(iconText);
			
			if (faceImg is TempBitmap)
			{
				faceImg.addEventListener(Event.COMPLETE,onImgComplete);
			}
		}
		
		private function onImgComplete(event:Event):void
		{
			event.target.removeEventListener(Event.COMPLETE,onImgComplete);
			iconText.width = faceImg.width;
		}
	}
}